﻿package cn.flashk.image
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class ImageDecode extends Object
    {
        private var ldr:Loader;
        private var callFun:Function;

        public function ImageDecode(param1:ByteArray, param2:Function)
        {
            callFun = param2;
            ldr = new Loader();
            ldr.contentLoaderInfo.addEventListener(Event.INIT, callBack);
            ldr.loadBytes(param1);
            return;
        }// end function

        private function callBack(event:Event) : void
        {
            callFun(ldr.content as Bitmap);
            ldr.contentLoaderInfo.removeEventListener(Event.INIT, callBack);
            Bitmap(ldr.content).bitmapData.dispose();
            ldr.unload();
            ldr = null;
            callFun = null;
            return;
        }// end function

        public static function toBitmapData(param1:ByteArray) : Loader
        {
            var _loc_2:* = new Loader();
            _loc_2.loadBytes(param1);
            return _loc_2;
        }// end function

    }
}
